package cn.kgc.service.Impl;

import cn.kgc.dao.AirQualityIndexMapper;
import cn.kgc.entity.AirQualityIndex;
import cn.kgc.service.AirQualityIndexService;
import cn.kgc.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AirQualityIndexImpl implements AirQualityIndexService {
    @Autowired
    private AirQualityIndexMapper airQualityIndexMapper;
    @Autowired
    private DistrictService districtService;
    @Override
    public List<AirQualityIndex> airList() {

        List<AirQualityIndex> air =  airQualityIndexMapper.selectAll();
        for(AirQualityIndex a:air){
            Integer dis = a.getDistrictId();
            String DistrictName = districtService.selectNameById(dis);
            a.setDistrictName(DistrictName);
        }
        return air;
    }

    @Override
    public List<AirQualityIndex> find(Integer id) {
        AirQualityIndex air = new AirQualityIndex();
        air.setDistrictId(id);
        List<AirQualityIndex> find = airQualityIndexMapper.select(air);
        for(AirQualityIndex a:find){
            Integer dis = a.getDistrictId();
            String DistrictName = districtService.selectNameById(dis);
            a.setDistrictName(DistrictName);
        }
        return find;
    }

    @Override
    public boolean addAir(AirQualityIndex air) {
        air.setLastModifyTime(new Date());
        return airQualityIndexMapper.insert(air)>0;
    }
}
